class Solution
{
public:
    string convert(string s, int numRows)
    {
        if (numRows == 1 || numRows >= s.size())
            return s;

        vector<string> rows(numRows);
        int i = 0, k = -1;

        for (auto ss : s)
        {
            rows[i].push_back(ss);
            if (i == 0 || i == numRows - 1)
                k = -k;
            i += k;
        }
        string ans;
        for (auto& row : rows)
            ans += row;

        return ans;
    }
};